Skip to content

Thermostat example demonstrate advantages of source/sink vs shared in certain applications. #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2022

Conversation

aentinger
Copy link
Contributor

@aentinger aentinger commented Jul 19, 2022

This fixes #81.

This example demonstrates the merits of the source/sink paradigm in a application where there are multiple consumers (sinks) for a single producer (source). In this example a thermostat room control is simulated, which controls a heating device and an AC in two separate threads, based on the readings of one central temperature sensor (a bit contrived, but illustrative example).

@aentinger aentinger added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Jul 19, 2022
@aentinger aentinger requested a review from pnndra July 19, 2022 08:26
@aentinger aentinger self-assigned this Jul 19, 2022
@aentinger aentinger marked this pull request as draft July 19, 2022 11:41
@arduino-libraries arduino-libraries deleted a comment from github-actions bot Jul 19, 2022
@arduino-libraries arduino-libraries deleted a comment from github-actions bot Jul 19, 2022
@arduino-libraries arduino-libraries deleted a comment from github-actions bot Jul 19, 2022
@aentinger aentinger force-pushed the source/sink-example branch from d1a57a7 to 8564a6b Compare July 20, 2022 11:20
@github-actions
Copy link

Memory usage change @ 8564a6b

Board flash % RAM for global variables %
arduino:mbed_nano:nano33ble 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m4 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/Threading_Basics/Shared_Counter
flash
% examples/Threading_Basics/Shared_Counter
RAM for global variables
% examples/Threading_Basics/Source_Sink_Counter
flash
% examples/Threading_Basics/Source_Sink_Counter
RAM for global variables
% examples/Threading_Basics/Source_Sink_LED
flash
% examples/Threading_Basics/Source_Sink_LED
RAM for global variables
% examples/Threading_Basics/Thermostat
flash
% examples/Threading_Basics/Thermostat
RAM for global variables
% examples/Threadsafe_IO/SPI
flash
% examples/Threadsafe_IO/SPI
RAM for global variables
% examples/Threadsafe_IO/SPI_BusIO
flash
% examples/Threadsafe_IO/SPI_BusIO
RAM for global variables
% examples/Threadsafe_IO/Serial_GlobalPrefixSuffix
flash
% examples/Threadsafe_IO/Serial_GlobalPrefixSuffix
RAM for global variables
% examples/Threadsafe_IO/Serial_ProtocolWrapping
flash
% examples/Threadsafe_IO/Serial_ProtocolWrapping
RAM for global variables
% examples/Threadsafe_IO/Serial_Reader
flash
% examples/Threadsafe_IO/Serial_Reader
RAM for global variables
% examples/Threadsafe_IO/Serial_Writer
flash
% examples/Threadsafe_IO/Serial_Writer
RAM for global variables
% examples/Threadsafe_IO/Wire
flash
% examples/Threadsafe_IO/Wire
RAM for global variables
% examples/Threadsafe_IO/Wire_BusIO
flash
% examples/Threadsafe_IO/Wire_BusIO
RAM for global variables
%
arduino:mbed_nano:nano33ble 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 N/A N/A N/A N/A 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 N/A N/A N/A N/A 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_portenta:envie_m4 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 N/A N/A N/A N/A 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_portenta:envie_m7 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 N/A N/A N/A N/A 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
Click for full report CSV
Board,examples/Threading_Basics/Shared_Counter<br>flash,%,examples/Threading_Basics/Shared_Counter<br>RAM for global variables,%,examples/Threading_Basics/Source_Sink_Counter<br>flash,%,examples/Threading_Basics/Source_Sink_Counter<br>RAM for global variables,%,examples/Threading_Basics/Source_Sink_LED<br>flash,%,examples/Threading_Basics/Source_Sink_LED<br>RAM for global variables,%,examples/Threading_Basics/Thermostat<br>flash,%,examples/Threading_Basics/Thermostat<br>RAM for global variables,%,examples/Threadsafe_IO/SPI<br>flash,%,examples/Threadsafe_IO/SPI<br>RAM for global variables,%,examples/Threadsafe_IO/SPI_BusIO<br>flash,%,examples/Threadsafe_IO/SPI_BusIO<br>RAM for global variables,%,examples/Threadsafe_IO/Serial_GlobalPrefixSuffix<br>flash,%,examples/Threadsafe_IO/Serial_GlobalPrefixSuffix<br>RAM for global variables,%,examples/Threadsafe_IO/Serial_ProtocolWrapping<br>flash,%,examples/Threadsafe_IO/Serial_ProtocolWrapping<br>RAM for global variables,%,examples/Threadsafe_IO/Serial_Reader<br>flash,%,examples/Threadsafe_IO/Serial_Reader<br>RAM for global variables,%,examples/Threadsafe_IO/Serial_Writer<br>flash,%,examples/Threadsafe_IO/Serial_Writer<br>RAM for global variables,%,examples/Threadsafe_IO/Wire<br>flash,%,examples/Threadsafe_IO/Wire<br>RAM for global variables,%,examples/Threadsafe_IO/Wire_BusIO<br>flash,%,examples/Threadsafe_IO/Wire_BusIO<br>RAM for global variables,%
arduino:mbed_nano:nano33ble,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,N/A,N/A,N/A,N/A,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,N/A,N/A,N/A,N/A,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_portenta:envie_m4,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,N/A,N/A,N/A,N/A,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_portenta:envie_m7,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,N/A,N/A,N/A,N/A,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0

@aentinger aentinger marked this pull request as ready for review July 20, 2022 11:33
@pnndra
Copy link
Contributor

pnndra commented Jul 21, 2022

nice example but i don't see why you have a single inot for temperature control and instantiate it twice, eventually passing it different strings to print out a different report. in order to allow setting the string we may add a public function to set name so that you can set it up from the instance object

@aentinger
Copy link
Contributor Author

I agree that the example is a bit contrived. But you've misread it, the two temperature controls are for different things. One controls the heating the other controls an air-conditioner. Maybe I should adapt inot-naming and redesign the example a bit to be more easily "graspable".

@github-actions
Copy link

Memory usage change @ 1e5a95a

Board flash % RAM for global variables %
arduino:mbed_nano:nano33ble 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m4 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/Threading_Basics/Shared_Counter
flash
% examples/Threading_Basics/Shared_Counter
RAM for global variables
% examples/Threading_Basics/Source_Sink_Counter
flash
% examples/Threading_Basics/Source_Sink_Counter
RAM for global variables
% examples/Threading_Basics/Source_Sink_LED
flash
% examples/Threading_Basics/Source_Sink_LED
RAM for global variables
% examples/Threading_Basics/Thermostat
flash
% examples/Threading_Basics/Thermostat
RAM for global variables
% examples/Threadsafe_IO/SPI
flash
% examples/Threadsafe_IO/SPI
RAM for global variables
% examples/Threadsafe_IO/SPI_BusIO
flash
% examples/Threadsafe_IO/SPI_BusIO
RAM for global variables
% examples/Threadsafe_IO/Serial_GlobalPrefixSuffix
flash
% examples/Threadsafe_IO/Serial_GlobalPrefixSuffix
RAM for global variables
% examples/Threadsafe_IO/Serial_ProtocolWrapping
flash
% examples/Threadsafe_IO/Serial_ProtocolWrapping
RAM for global variables
% examples/Threadsafe_IO/Serial_Reader
flash
% examples/Threadsafe_IO/Serial_Reader
RAM for global variables
% examples/Threadsafe_IO/Serial_Writer
flash
% examples/Threadsafe_IO/Serial_Writer
RAM for global variables
% examples/Threadsafe_IO/Wire
flash
% examples/Threadsafe_IO/Wire
RAM for global variables
% examples/Threadsafe_IO/Wire_BusIO
flash
% examples/Threadsafe_IO/Wire_BusIO
RAM for global variables
%
arduino:mbed_nano:nano33ble 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 N/A N/A N/A N/A 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 N/A N/A N/A N/A 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_portenta:envie_m4 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 N/A N/A N/A N/A 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_portenta:envie_m7 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 N/A N/A N/A N/A 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
Click for full report CSV
Board,examples/Threading_Basics/Shared_Counter<br>flash,%,examples/Threading_Basics/Shared_Counter<br>RAM for global variables,%,examples/Threading_Basics/Source_Sink_Counter<br>flash,%,examples/Threading_Basics/Source_Sink_Counter<br>RAM for global variables,%,examples/Threading_Basics/Source_Sink_LED<br>flash,%,examples/Threading_Basics/Source_Sink_LED<br>RAM for global variables,%,examples/Threading_Basics/Thermostat<br>flash,%,examples/Threading_Basics/Thermostat<br>RAM for global variables,%,examples/Threadsafe_IO/SPI<br>flash,%,examples/Threadsafe_IO/SPI<br>RAM for global variables,%,examples/Threadsafe_IO/SPI_BusIO<br>flash,%,examples/Threadsafe_IO/SPI_BusIO<br>RAM for global variables,%,examples/Threadsafe_IO/Serial_GlobalPrefixSuffix<br>flash,%,examples/Threadsafe_IO/Serial_GlobalPrefixSuffix<br>RAM for global variables,%,examples/Threadsafe_IO/Serial_ProtocolWrapping<br>flash,%,examples/Threadsafe_IO/Serial_ProtocolWrapping<br>RAM for global variables,%,examples/Threadsafe_IO/Serial_Reader<br>flash,%,examples/Threadsafe_IO/Serial_Reader<br>RAM for global variables,%,examples/Threadsafe_IO/Serial_Writer<br>flash,%,examples/Threadsafe_IO/Serial_Writer<br>RAM for global variables,%,examples/Threadsafe_IO/Wire<br>flash,%,examples/Threadsafe_IO/Wire<br>RAM for global variables,%,examples/Threadsafe_IO/Wire_BusIO<br>flash,%,examples/Threadsafe_IO/Wire_BusIO<br>RAM for global variables,%
arduino:mbed_nano:nano33ble,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,N/A,N/A,N/A,N/A,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,N/A,N/A,N/A,N/A,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_portenta:envie_m4,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,N/A,N/A,N/A,N/A,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_portenta:envie_m7,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,N/A,N/A,N/A,N/A,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0

@aentinger aentinger merged commit 95ed912 into main Jul 25, 2022
@aentinger aentinger deleted the source/sink-example branch July 25, 2022 08:56
@pnndra
Copy link
Contributor

pnndra commented Jul 25, 2022

i still think it would be useful to show how the same block of code can be reused, which this example fails to show.
regarding the AC/heating differences, these are minimal and can be easily parametrized, which would make code reusability much more evident.
my proposal is to refactor code to have a single inot that handles temperature regulation by adding a parameter for the threshold, one for the hysteresis and one for the polarity of the control and then use two times the same code with different parameters to handle the two devices.
as i was mentioning we should be able to add public methods to set parameters and allow the main sketch to customize algorithm functionality before the start method is called.

@per1234 per1234 added topic: documentation Related to documentation for the project and removed topic: code Related to content of the project itself labels Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: documentation Related to documentation for the project type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create example to highlight advantages of sink/source semantics in certain use cases.
3 participants